package com.java.action;


import java.util.List;

import com.java.service.IDeptService;
import com.opensymphony.xwork2.ActionSupport;
import com.training.pojo.chengshu.UDept;


public class ModifyDeptAction extends ActionSupport {
	
    private IDeptService deptService; 
    private UDept pp;
    private UDept dept;
    private String msg;

    public String execute(){
    	List<UDept> list = deptService.list1();
        String s = pp.getDeptname();
        String ss = null;
        if(s==null||s==""){
        	msg = "部门名称不能为空";
        }else{
        	int flag=0;
			if (list != null) {
				for (UDept d : list) {
					if (s.equals(d.getDeptname())) {
						flag=1;
						
					} 
					if(flag==1){
						msg = "部门名称已经存在";
						ss = "fail";
					}else {
					    dept  = deptService.updateDept(pp);
						System.out.println("add成功");
						msg = "修改成功";
						ss = "success";
					}
				}
			}else{
				boolean b = deptService.addDept(dept);
				System.out.println("add成功");
				ss = "success";
			}
        } 
        return ss;
    }
	public IDeptService getDeptService() {
		return deptService;
	}

	public void setDeptService(IDeptService deptService) {
		this.deptService = deptService;
	}
	public UDept getPp() {
		return pp;
	}
	public void setPp(UDept pp) {
		this.pp = pp;
	}
	public UDept getDept() {
		return dept;
	}
	public void setDept(UDept dept) {
		this.dept = dept;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
}
